﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ElectronicJournal.DB.Item;
using ElectronicJournal.DB;

namespace ElectronicJournal
{
    public class ThemeLoader
    {
        public static string LoadCSS()
        {
            DBTheme dbTheme = new DBTheme();
            string css;
            ItemTheme theme = dbTheme.GetTheme();
            css = "<style type=\"text/css\">";
            css += "\n" +"  body   ";
            css += "\n" +"     {   ";
            if (theme.backgroundcolor != "")
                css += "\n" + "background-color:#" + theme.backgroundcolor + ";";
            if (theme.color != "")
                css += "\n" + "color:#" + theme.color + ";";
            if (theme.backgroundimage != "")
                css += "\n" + "background-image: url(\"/Styles/" + theme.backgroundimage + "\");";
            css += "\n" +"     }   ";
            if (theme.logoheader != "")
            {
                css += "\n" + "  .logo   ";
                css += "\n" + "     {   ";
                css += "\n" + "         background: url(\"/Styles/" + theme.logoheader + "\") no-repeat;";
                css += "\n" + "     }   ";
            }
            if (theme.bgimgtopleft != "")
            {
                css += "\n" + "  .topleft  ";
                css += "\n" + "    {   ";
                css += "\n" + "        background-image: url(\"/Styles/" + theme.bgimgtopleft + "\");";
                css += "\n" + "    }";
            }
            if (theme.bgimgtopright != "")
            {
                css += "\n" + "  .topright  ";
                css += "\n" + "    {   ";
	            css += "\n" + "        background-image: url(\"/Styles/"+theme.bgimgtopright+"\");";
                css += "\n" + "    }";
            }
            if (theme.bgimgright != "")
            {
                css += "\n" + "  .colright  ";
                css += "\n" + "    {   ";
                css += "\n" + "        background-image: url(\"/Styles/" + theme.bgimgright + "\");";
                css += "\n" + "    }";
            }
            if (theme.bgimgleft != "")
            {
                css += "\n" + "  .colleft  ";
                css += "\n" + "    {   ";
                css += "\n" + "        background-image: url(\"/Styles/" + theme.bgimgleft + "\");";
                css += "\n" + "    }";
            }
            if (theme.bgimgbottomright != "")
            {
                css += "\n" + "  .bottomright  ";
                css += "\n" + "    {   ";
                css += "\n" + "        background-image: url(\"/Styles/" + theme.bgimgbottomright + "\");";
                css += "\n" + "    }";
            }
            if (theme.bgimgbottomleft != "")
            {
                css += "\n" + "  .bottomleft  ";
                css += "\n" + "    {   ";
                css += "\n" + "        background-image: url(\"/Styles/" + theme.bgimgbottomleft + "\");";
                css += "\n" + "    }";
            }

            css += "\n" + "  .bottom  ";
            css += "\n" + "    {   ";
            if (theme.bgimgbottom != "")
                css += "\n" + "        background-image: url(\"/Styles/" + theme.bgimgbottom + "\");";
            css += "\n" + "    }";

            css += "\n" + "  div.menu ul li a, div.menu ul li a:visited ";
            css += "\n" + "    {   ";
            if (theme.bgcolormenuitem != "")
                css += "\n" + "background-color:#" + theme.bgcolormenuitem + ";";
            if (theme.bordercolormenuitem != "")
                css += "\n" + "border-color:#" + theme.bordercolormenuitem + ";";
            if (theme.colormenuitem != "")
                css += "\n" + "color:#" + theme.colormenuitem + ";";
            css += "\n" + "    }";

            css += "\n" + "  div.hideSkiplink ";
            css += "\n" + "    {   ";
            if (theme.bgcolormenu != "")
                css += "\n" + "background-color:#" + theme.bgcolormenu + ";";
            css += "\n" + "    }";

            css += "\n" + "  .footer ";
            css += "\n" + "    {   ";
            if (theme.bgcolorfooter != "")
                css += "\n" + "background-color:#" + theme.bgcolorfooter + ";";
            css += "\n" + "    }";

            css += "\n" + "</style>";
            return css;
        }
        
    }
}